home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / MEMBLOCK.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  4KB  |  94 lines

  1. @echo OFF
  2. REM *************************************************************************
  3. REM *** MemBlock - Examples CEnvi DOS program to walk through the list of ***
  4. REM *** ver.1      allocated memory.  This uses interrupts through the    ***
  5. REM ***            interrupt() function, and direct memory access using   ***
  6. REM ***            peekbuf().  The following is a walk-through of your    ***
  7. REM ***            allocated memory blocks:                               ***
  8. REM *************************************************************************
  9. CEnvi %0.bat
  10. GOTO CENVI_EXIT
  11.  
  12. #define  MCB_HEADER_SIZE   16
  13. #define  ID_OFFSET         0
  14. #define  MORE_TO_FOLLOW    'M'   // set if more MCB follow in chain
  15. #define  LAST_MCB          'Z'   // if no more MCB in chain
  16. #define  PSP_SEG_OFFSET    1
  17. #define  SIZE_OFFSET       3
  18. #define  ENVIRONMENT_SEG_OFFSET  0x2C
  19.  
  20. /*************************************************************/
  21. /* Get access to the first memory block through undocumented */
  22. /* DOS interrupt to get the DIB (Dos Information Block.      */
  23. /*************************************************************/
  24. reg.ah = 0x52           // Get DIB address in ES:BX
  25. interrupt(0x21,reg)
  26. // The actual first mcb (memory control block) address is 4 bytes below
  27. // es:bx, or 16 bytes above the previous paragraph
  28. segment = PeekWord(reg.es - 1,reg.bx+14)
  29.  
  30.  
  31. /*************************************************************/
  32. /* Loop through all MCB's, displaying information about them */
  33. /*************************************************************/
  34. count = 0
  35. total = 0
  36. do {
  37.    printf("==========================================\n")
  38.    id = peek(Address(segment,ID_OFFSET))
  39.    printf("MCB number\t= %d\n",++count)
  40.    printf("ID\t\t= %c\n",id)
  41.    printf("MCB address\t= %04X:0000\n",segment)
  42.    printf("Memory address\t= %04X:0000\n",MemorySeg = segment+1)
  43.    printf("PSP address\t= %04X:0000\n",PspSeg = PeekWord(segment,PSP_SEG_OFFSET))
  44.    size = PeekWord(segment,SIZE_OFFSET)
  45.    printf("Size\t\t= %d paragraphs (%d bytes)\n",size,size*16)
  46.    if ( 0 != PSPSeg ) {
  47.       EnvironmentBlock = PeekWord(PspSeg,ENVIRONMENT_SEG_OFFSET)
  48.       if EnvironmentBlock == MemorySeg
  49.          ShowEnvironmentBlock(EnvironmentBlock)
  50.    }
  51.    // increment segment to point to the next MCB
  52.    segment += size + 1
  53.    total += size + 1
  54. } while( id == MORE_TO_FOLLOW )
  55.  
  56.  
  57. /***************/
  58. /* SHOW TOTALS */
  59. /***************/
  60. printf("==========================================\n")
  61. printf("Totals:\n")
  62. printf("MCB Count\t= %d\n",count)
  63. printf("Memory\t\t= %d paragraphs (%d bytes)\n",total,total*16)
  64.  
  65.  
  66. /*****************************************/
  67. /* FUNCTION TO DISPLAY ENVIRONMENT BLOCK */
  68. /*****************************************/
  69. ShowEnvironmentBlock(seg)
  70. {
  71.    printf("Environment block at %04X:0000\n",seg)
  72.    for ( Offset = 0; 0 != peek(Address(seg,Offset)); Offset++ ) {
  73.       EString = peek(Address(seg,Offset),1000)
  74.       Offset += strlen(EString)
  75.       printf(" %s\n",EString)
  76.    }
  77.    printf("Program: ")
  78.    if ( 0x0001 == PeekWord(seg,++Offset) ) {
  79.       // the full path and name of the calling program follows
  80.       printf("%s\n",peek(Address(seg,Offset+2),1000))
  81.    } else
  82.       printf("Unknown\n")
  83. }
  84.  
  85. /***********************************************/
  86. /* UTILITY FUNCTIONS USED IN THE ABOVE PROGRAM */
  87. /***********************************************/
  88. PeekWord(segment,offset)
  89. {
  90.    return( peek(Address(segment,offset),UWORD16) );
  91. }
  92.  
  93. :CENVI_EXIT
  94.